import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/h5/inviteFriend',
      name: 'InviteFriend',
      component: () => import('/@/views/h5/invite/InviteFriend.vue'),
      meta: {
        title: '邀请好友',
      },
    },
    {
      path: '/h5/workCoin/mine',
      name: 'WorkCoinMine',
      component: () => import('/@/views/h5/workCoin/Mine.vue'),
      meta: {
        title: '我的工币',
      },
    },
    {
      path: '/h5/workCoin/bill',
      name: 'WorkCoinBill',
      component: () => import('/@/views/h5/workCoin/Bill.vue'),
      meta: {
        title: '账单',
      },
    },
    {
      path: '/h5/announce',
      name: 'Announce',
      component: () => import('/@/views/h5/announce/Announce.vue'),
      meta: {
        title: '公告',
      },
    },
    {
      path: '/h5/announceDetail',
      name: 'AnnounceDetail',
      component: () => import('/@/views/h5/announce/AnnounceDetail.vue'),
      meta: {
        title: '公告详情',
      },
    },
    {
      path: '/h5/project/pp',
      name: 'PioneerPartnerProject',
      component: () => import('/@/views/h5/project/PioneerPartner.vue'),
      meta: {
        title: '先锋伙伴计划',
      },
    },
    {
      path: '/h5/project/ep',
      name: 'EcologicalPlanProject',
      component: () => import('/@/views/h5/project/EcologicalPlan.vue'),
      meta: {
        title: '生态规划',
      },
    },
    {
      path: '/h5/form/avatar',
      name: 'AvatarForm',
      component: () => import('/@/views/h5/form/Avatar.vue'),
      meta: {
        title: '用户头像设置',
      },
    },
  ],
})

router.beforeEach((to, from, next) => {
  if (to && to.meta && to.meta.title) {
    const title = document.querySelector('title')
    title.innerHTML = to.meta.title
  }
  next()
})

export default router
